package com.woniuxy.creditsystem.common.mapper;

import com.woniuxy.creditsystem.common.bean.CreditRecordInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @author ：zhengbin
 * @date ：Created in 2020/12/12 0012
 * @description：
 * @modified By：
 * @version: 1.0v
 */

@Mapper
public interface RecordMapper {

    @Options(
            useGeneratedKeys = true,
            keyProperty = "c.id"
    )
    @Insert("insert into credit_record(content,comment,operating_time, fk_user_id,fk_apply_id)values(#{c.content},#{c.comment},#{c.operatingTime},#{c.fkUserId},#{c.fkAppyId}) ")
    int savaRecord(@Param("c") CreditRecordInfo creditRecordInfo);

    @ResultType(CreditRecordInfo.class)
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property ="userInfo" ,column = "fk_user_id",one = @One(select = "com.woniuxy.creditsystem.common.mapper.UserMapper.getNameById",fetchType = FetchType.LAZY)),
            @Result(property = "applyInfo",column = "fk_apply_id",one = @One(select = "com.woniuxy.creditsystem.common.mapper.ApplyMapper.findByID",fetchType = FetchType.LAZY))
    })
    @Select("select content,comment,operating_time as operatingTime, fk_user_id,fk_apply_id  from credit_record ")
    List<CreditRecordInfo> findAll();


   @Results({
           @Result(id = true,property = "id",column = "id"),
           @Result(property ="userInfo" ,column = "fk_user_id",one = @One(select = "com.woniuxy.creditsystem.common.bean.UserInfo",fetchType = FetchType.LAZY)),
           @Result(property = "applyInfo",column = "fk_apply_id",one = @One(select = "com.woniuxy.creditsystem.common.mapper.ApplyMapper.findByID",fetchType = FetchType.LAZY))
   })
    @Select("select content,comment,operating_time as operatingTime, fk_user_id,fk_apply_id   from credit_record where fk_appy_id =#{fkAppyId}")
    CreditRecordInfo findByid(long fkAppyId);
}
